package com.postsuperman.proxypool.parser;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.postsuperman.proxypool.common.enums.LevelEnum;
import com.postsuperman.proxypool.pojo.HttpProxy;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author ： Lwl postserupman
 * @Description TODO
 * @Date 2019/2/27 12:06
 * @Version 1.0
 */
public class ZmProxyParser implements IParser {

    @Override
    public List<HttpProxy> parser(String result) {
        if (StrUtil.isNotEmpty(result)) {
            try {
                JSONObject jsonObject = JSON.parseObject(result);
                Boolean success = jsonObject.getBoolean("success");
                if (success) {
                    String data = jsonObject.getString("data");
                    if (StrUtil.isNotEmpty(data)) {
                        List<HttpProxy> zmHttpProxies = JSONObject.parseArray(data, HttpProxy.class);
                        return zmHttpProxies;
                    }
                } else {
                    String msg = jsonObject.getString("msg");
                    throw new NullPointerException(msg);
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        return null;
    }
}
